//
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2010
// by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web;
using System.Web.Security;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Data;
using DotNetNuke.Entities.Controllers;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Profile;
using DotNetNuke.Security;
using DotNetNuke.Security.Membership;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Messaging.Data;
using DotNetNuke.Services.Messaging;
using PortalController = DotNetNuke.Entities.Portals.PortalController;

namespace DotNetNuke.Entities.Users
{
	public class UserController
	{
		private static DotNetNuke.Security.Membership.MembershipProvider memberProvider = DotNetNuke.Security.Membership.MembershipProvider.Instance();
		private static MessagingController _messagingController = new MessagingController();
		private static void AddEventLog(int portalId, string username, int userId, string portalName, string Ip, UserLoginStatus loginStatus)
		{
			Services.Log.EventLog.EventLogController objEventLog = new Services.Log.EventLog.EventLogController();
			Services.Log.EventLog.LogInfo objEventLogInfo = new Services.Log.EventLog.LogInfo();
			PortalSecurity objSecurity = new PortalSecurity();
			objEventLogInfo.AddProperty("IP", Ip);
			objEventLogInfo.LogPortalID = portalId;
			objEventLogInfo.LogPortalName = portalName;
			objEventLogInfo.LogUserName = objSecurity.InputFilter(username, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoAngleBrackets | PortalSecurity.FilterFlag.NoMarkup);
			objEventLogInfo.LogUserID = userId;
			objEventLogInfo.LogTypeKey = loginStatus.ToString();
			objEventLog.AddLog(objEventLogInfo);
		}
		private static object GetCachedUserByPortalCallBack(CacheItemArgs cacheItemArgs)
		{
			int portalId = (int)cacheItemArgs.ParamList[0];
			string username = (string)cacheItemArgs.ParamList[1];
			return memberProvider.GetUserByUserName(portalId, username);
		}
		static internal Hashtable GetUserSettings(Hashtable settings)
		{
			PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings();
			if (settings["Column_FirstName"] == null)
			{
				settings["Column_FirstName"] = false;
			}
			if (settings["Column_LastName"] == null)
			{
				settings["Column_LastName"] = false;
			}
			if (settings["Column_DisplayName"] == null)
			{
				settings["Column_DisplayName"] = true;
			}
			if (settings["Column_Address"] == null)
			{
				settings["Column_Address"] = true;
			}
			if (settings["Column_Telephone"] == null)
			{
				settings["Column_Telephone"] = true;
			}
			if (settings["Column_Email"] == null)
			{
				settings["Column_Email"] = false;
			}
			if (settings["Column_CreatedDate"] == null)
			{
				settings["Column_CreatedDate"] = true;
			}
			if (settings["Column_LastLogin"] == null)
			{
				settings["Column_LastLogin"] = false;
			}
			if (settings["Column_Authorized"] == null)
			{
				settings["Column_Authorized"] = true;
			}
			if (settings["Display_Mode"] == null)
			{
				settings["Display_Mode"] = DisplayMode.All;
			}
			else
			{
				settings["Display_Mode"] = (DisplayMode)settings["Display_Mode"];
			}
			if (settings["Display_SuppressPager"] == null)
			{
				settings["Display_SuppressPager"] = false;
			}
			if (settings["Records_PerPage"] == null)
			{
				settings["Records_PerPage"] = 10;
			}
			if (settings["Profile_DefaultVisibility"] == null)
			{
				settings["Profile_DefaultVisibility"] = UserVisibilityMode.AdminOnly;
			}
			else
			{
				settings["Profile_DefaultVisibility"] = (UserVisibilityMode)settings["Profile_DefaultVisibility"];
			}
			if (settings["Profile_DisplayVisibility"] == null)
			{
				settings["Profile_DisplayVisibility"] = true;
			}
			if (settings["Profile_ManageServices"] == null)
			{
				settings["Profile_ManageServices"] = true;
			}
			if (settings["Redirect_AfterLogin"] == null)
			{
				settings["Redirect_AfterLogin"] = -1;
			}
			if (settings["Redirect_AfterRegistration"] == null)
			{
				settings["Redirect_AfterRegistration"] = -1;
			}
			if (settings["Redirect_AfterLogout"] == null)
			{
				settings["Redirect_AfterLogout"] = -1;
			}
			if (settings["Security_CaptchaLogin"] == null)
			{
				settings["Security_CaptchaLogin"] = false;
			}
			if (settings["Security_CaptchaRegister"] == null)
			{
				settings["Security_CaptchaRegister"] = false;
			}
			if (settings["Security_EmailValidation"] == null)
			{
				settings["Security_EmailValidation"] = DotNetNuke.Common.Globals.glbEmailRegEx;
			}
			if (settings["Security_RequireValidProfile"] == null)
			{
				settings["Security_RequireValidProfile"] = false;
			}
			if (settings["Security_RequireValidProfileAtLogin"] == null)
			{
				settings["Security_RequireValidProfileAtLogin"] = true;
			}
			if (settings["Security_UsersControl"] == null)
			{
				if (_portalSettings != null && _portalSettings.Users > 1000)
				{
					settings["Security_UsersControl"] = UsersControl.TextBox;
				}
				else
				{
					settings["Security_UsersControl"] = UsersControl.Combo;
				}
			}
			else
			{
				settings["Security_UsersControl"] = (UsersControl)settings["Security_UsersControl"];
			}
			if (settings["Security_DisplayNameFormat"] == null)
			{
				settings["Security_DisplayNameFormat"] = "";
			}
			return settings;
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// GetUserCountByPortalCallBack gets the number of users associates to a portal from the the Database.
		/// and sets the cache.
		/// </summary>
		/// <param name="cacheItemArgs">The CacheItemArgs object that contains the parameters
		/// needed for the database call</param>
		/// <history>
		/// 	[pbeadle]	02/09/2011    
		/// </history>
		/// -----------------------------------------------------------------------------
		private static object GetUserCountByPortalCallBack(CacheItemArgs cacheItemArgs)
		{
			int _portalId = (int)cacheItemArgs.ParamList[0];
			int portalUserCount = memberProvider.GetUserCountByPortal(_portalId);
			DataCache.SetCache(cacheItemArgs.CacheKey, portalUserCount);
			return portalUserCount;
		}

		public static bool ChangePassword(UserInfo user, string oldPassword, string newPassword)
		{
			bool retValue = Null.NullBoolean;
			if (ValidatePassword(newPassword))
			{
				retValue = memberProvider.ChangePassword(user, oldPassword, newPassword);
				user.Membership.UpdatePassword = false;
				UpdateUser(user.PortalID, user);
			}
			else
			{
				throw new Exception("Invalid Password");
			}
			return retValue;
		}
		public static bool ChangePasswordQuestionAndAnswer(UserInfo user, string password, string passwordQuestion, string passwordAnswer)
		{
			Services.Log.EventLog.EventLogController objEventLog = new Services.Log.EventLog.EventLogController();
			objEventLog.AddLog(user, PortalController.GetCurrentPortalSettings(), UserController.GetCurrentUserInfo().UserID, "", DotNetNuke.Services.Log.EventLog.EventLogController.EventLogType.USER_UPDATED);
			return memberProvider.ChangePasswordQuestionAndAnswer(user, password, passwordQuestion, passwordAnswer);
		}
		public static void CheckInsecurePassword(string Username, string Password, ref UserLoginStatus loginStatus)
		{
			if (Username == "admin" && (Password == "admin" || Password == "dnnadmin"))
			{
				loginStatus = UserLoginStatus.LOGIN_INSECUREADMINPASSWORD;
			}
			if (Username == "host" && (Password == "host" || Password == "dnnhost"))
			{
				loginStatus = UserLoginStatus.LOGIN_INSECUREHOSTPASSWORD;
			}
		}
		public static UserCreateStatus CreateUser(ref UserInfo objUser)
		{
			UserCreateStatus createStatus = UserCreateStatus.AddUser;
			createStatus = memberProvider.CreateUser(ref objUser);
			if (createStatus == UserCreateStatus.Success)
			{
				Services.Log.EventLog.EventLogController objEventLog = new Services.Log.EventLog.EventLogController();
				objEventLog.AddLog(objUser, PortalController.GetCurrentPortalSettings(), UserController.GetCurrentUserInfo().UserID, "", Services.Log.EventLog.EventLogController.EventLogType.USER_CREATED);
				DataCache.ClearPortalCache(objUser.PortalID, false);
				if (!objUser.IsSuperUser)
				{
					RoleController objRoles = new RoleController();
					RoleInfo objRole;
					ArrayList arrRoles = objRoles.GetPortalRoles(objUser.PortalID);
					int i;
					for (i = 0; i <= arrRoles.Count - 1; i++)
					{
						objRole = (RoleInfo)arrRoles[i];
						if (objRole.AutoAssignment == true)
						{
							objRoles.AddUserRole(objUser.PortalID, objUser.UserID, objRole.RoleID, Null.NullDate, Null.NullDate);
						}
					}
				}
			}
			return createStatus;
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// Restores an existing User from the Data Store
		/// </summary>
		/// <remarks></remarks>
		/// <param name="objUser">The userInfo object to restore from the Database</param>
		/// <returns>A Boolean value that indicates whether the User was successfully restored</returns>
		/// <history>
		/// 	[aprasad]	2/15/2011	Created
		/// </history>
		/// -----------------------------------------------------------------------------
		public static bool RestoreUser(UserInfo objUser)
		{

			bool retValue = false;

			//Restore the User
			retValue = memberProvider.RestoreUser(objUser);

			if ((retValue))
			{
				// Obtain PortalSettings from Current Context
				PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings();

				//Log event
				Services.Log.EventLog.EventLogController objEventLog = new Services.Log.EventLog.EventLogController();
				objEventLog.AddLog("Username", objUser.Username, _portalSettings, objUser.UserID, Services.Log.EventLog.EventLogController.EventLogType.USER_RESTORED);

				DataCache.ClearPortalCache(objUser.PortalID, false);
				DataCache.ClearUserCache(objUser.PortalID, objUser.Username);
			}

			return retValue;

		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// Permanently Remove Soft-Deleted User from the Data Store
		/// </summary>
		/// <remarks></remarks>
		/// <param name="objUser">The userInfo object to remove from the Database</param>
		/// <returns>A Boolean value that indicates whether the User was successfully removed</returns>
		/// <history>
		/// 	[aprasad]	2/15/2011	Created
		/// </history>
		/// -----------------------------------------------------------------------------
		public static bool RemoveUser(UserInfo objUser)
		{

			bool retValue = false;

			//Restore the User
			retValue = memberProvider.RemoveUser(objUser);

			if ((retValue))
			{
				// Obtain PortalSettings from Current Context
				PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings();

				//Log event
				Services.Log.EventLog.EventLogController objEventLog = new Services.Log.EventLog.EventLogController();
				objEventLog.AddLog("Username", objUser.Username, _portalSettings, objUser.UserID, Services.Log.EventLog.EventLogController.EventLogType.USER_REMOVED);

				DataCache.ClearPortalCache(objUser.PortalID, false);
				DataCache.ClearUserCache(objUser.PortalID, objUser.Username);
			}

			return retValue;

		}

		public static bool DeleteUser(ref UserInfo objUser, bool notify, bool deleteAdmin)
		{
			bool CanDelete = true;
			IDataReader dr = null;
			try
			{
				dr = DataProvider.Instance().GetPortal(objUser.PortalID, PortalController.GetActivePortalLanguage(objUser.PortalID));
				if (dr.Read())
				{
					if (objUser.UserID == Convert.ToInt32(dr["AdministratorId"]))
					{
						CanDelete = deleteAdmin;
					}
				}
				if (CanDelete)
				{
					FolderPermissionController.DeleteFolderPermissionsByUser(objUser);
					ModulePermissionController.DeleteModulePermissionsByUser(objUser);
					TabPermissionController.DeleteTabPermissionsByUser(objUser);
					CanDelete = memberProvider.DeleteUser(objUser);
				}
				if (CanDelete)
				{
					PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings();
					Services.Log.EventLog.EventLogController objEventLog = new Services.Log.EventLog.EventLogController();
					objEventLog.AddLog("Username", objUser.Username, _portalSettings, objUser.UserID, Services.Log.EventLog.EventLogController.EventLogType.USER_DELETED);
					if (notify && !objUser.IsSuperUser)
					{
						Message _message = new Message();
						_message.FromUserID = _portalSettings.AdministratorId;
						_message.ToUserID = _portalSettings.AdministratorId;
						_message.Subject = Localization.GetSystemMessage(objUser.Profile.PreferredLocale, _portalSettings, "EMAIL_USER_UNREGISTER_SUBJECT", objUser, Localization.GlobalResourceFile, null, "", _portalSettings.AdministratorId);
						_message.Body = Localization.GetSystemMessage(objUser.Profile.PreferredLocale, _portalSettings, "EMAIL_USER_UNREGISTER_BODY", objUser, Localization.GlobalResourceFile, null, "", _portalSettings.AdministratorId);
						_message.Status = MessageStatusType.Unread;
						//_messagingController.SaveMessage(_message);
						Services.Mail.Mail.SendEmail(_portalSettings.Email, _portalSettings.Email, _message.Subject, _message.Body);
					}
					DataCache.ClearPortalCache(objUser.PortalID, false);
					DataCache.ClearUserCache(objUser.PortalID, objUser.Username);
				}
			}
			catch (Exception Exc)
			{
				DotNetNuke.Services.Exceptions.Exceptions.LogException(Exc);
				CanDelete = false;
			}
			finally
			{
				CBO.CloseDataReader(dr, true);
			}
			return CanDelete;
		}
		public static void DeleteUsers(int portalId, bool notify, bool deleteAdmin)
		{
			ArrayList arrUsers = GetUsers(portalId);
			for (int i = 0; i < arrUsers.Count; i++)
			{
				UserInfo objUser = arrUsers[i] as UserInfo;
				DeleteUser(ref objUser, notify, deleteAdmin);
			}
		}
		public static void DeleteUnauthorizedUsers(int portalId)
		{
			ArrayList arrUsers = GetUsers(portalId);
			for (int i = 0; i < arrUsers.Count; i++)
			{
				UserInfo objUser = arrUsers[i] as UserInfo;
				if (objUser.Membership.Approved == false || objUser.Membership.LastLoginDate == Null.NullDate)
				{
					DeleteUser(ref objUser, true, false);
				}
			}
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// Permanently removes soft-deleted users for a Portal
		/// </summary>
		/// <remarks></remarks>
		/// <param name="portalId">The Id of the Portal</param>
		/// <history>
		/// 	[aprasad]	2/15/2011	Created
		/// </history>
		/// -----------------------------------------------------------------------------

		public static void RemoveDeletedUsers(int portalId)
		{
			ArrayList arrUsers = GetUsers(true, false, portalId);

			foreach (UserInfo objUser in arrUsers)
			{
				if (objUser.IsDeleted)
				{
					RemoveUser(objUser);
				}
			}

		}

		public static ArrayList FillUserCollection(int portalId, IDataReader dr, ref int totalRecords)
		{
			ArrayList arrUsers = new ArrayList();
			try
			{
				UserInfo obj;
				while (dr.Read())
				{
					obj = FillUserInfo(portalId, dr, false);
					arrUsers.Add(obj);
				}
				bool nextResult = dr.NextResult();
				totalRecords = DotNetNuke.Common.Globals.GetTotalRecords(ref dr);
			}
			catch (Exception exc)
			{
				DotNetNuke.Services.Exceptions.Exceptions.LogException(exc);
			}
			finally
			{
				CBO.CloseDataReader(dr, true);
			}
			return arrUsers;
		}
		public static ArrayList FillUserCollection(int portalId, IDataReader dr)
		{
			ArrayList arrUsers = new ArrayList();
			try
			{
				UserInfo obj;
				while (dr.Read())
				{
					obj = FillUserInfo(portalId, dr, false);
					arrUsers.Add(obj);
				}
			}
			catch (Exception exc)
			{
				DotNetNuke.Services.Exceptions.Exceptions.LogException(exc);
			}
			finally
			{
				CBO.CloseDataReader(dr, true);
			}
			return arrUsers;
		}
		public static UserInfo FillUserInfo(int portalId, IDataReader dr, bool closeDataReader)
		{
			UserInfo objUserInfo = null;
			try
			{
				bool bContinue = true;
				if (closeDataReader)
				{
					bContinue = false;
					if (dr.Read())
					{
						if (string.Equals(dr.GetName(0), "UserID", StringComparison.InvariantCultureIgnoreCase))
						{
							bContinue = true;
						}
					}
				}
				if (bContinue)
				{
					objUserInfo = new UserInfo();
					objUserInfo.PortalID = portalId;
					objUserInfo.IsSuperUser = Null.SetNullBoolean(dr["IsSuperUser"]);
					objUserInfo.IsDeleted = Null.SetNullBoolean(dr["IsDeleted"]);
					objUserInfo.UserID = Null.SetNullInteger(dr["UserID"]);
					objUserInfo.FirstName = Null.SetNullString(dr["FirstName"]);
					objUserInfo.LastName = Null.SetNullString(dr["LastName"]);
					objUserInfo.RefreshRoles = Null.SetNullBoolean(dr["RefreshRoles"]);
					objUserInfo.DisplayName = Null.SetNullString(dr["DisplayName"]);
					objUserInfo.AffiliateID = Null.SetNullInteger(Null.SetNull(dr["AffiliateID"], objUserInfo.AffiliateID));
					objUserInfo.Username = Null.SetNullString(dr["Username"]);
					GetUserMembership(objUserInfo);
					objUserInfo.Email = Null.SetNullString(dr["Email"]);
					objUserInfo.Membership.UpdatePassword = Null.SetNullBoolean(dr["UpdatePassword"]);
					if (!objUserInfo.IsSuperUser)
					{
						objUserInfo.Membership.Approved = Null.SetNullBoolean(dr["Authorised"]);
					}
				}
			}
			finally
			{
				CBO.CloseDataReader(dr, closeDataReader);
			}
			return objUserInfo;
		}
		public static string GeneratePassword()
		{
			return GeneratePassword(MembershipProviderConfig.MinPasswordLength + 4);
		}
		public static string GeneratePassword(int length)
		{
			return memberProvider.GeneratePassword(length);
		}
		public static UserInfo GetCachedUser(int portalId, string username)
		{
			string cacheKey = string.Format(DataCache.UserCacheKey, portalId, username);
			return CBO.GetCachedObject<UserInfo>(new CacheItemArgs(cacheKey, DataCache.UserCacheTimeOut, DataCache.UserCachePriority, portalId, username), GetCachedUserByPortalCallBack);
		}
		public static UserInfo GetCurrentUserInfo()
		{
			if ((HttpContext.Current == null))
			{
				if (!Thread.CurrentPrincipal.Identity.IsAuthenticated)
				{
					return new UserInfo();
				}
				else
				{
					PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings();
					if (_portalSettings != null)
					{
						UserInfo objUser = GetCachedUser(_portalSettings.PortalId, Thread.CurrentPrincipal.Identity.Name);
						if (objUser != null)
						{
							return objUser;
						}
						else
						{
							return new UserInfo();
						}
					}
					else
					{
						return new UserInfo();
					}
				}
			}
			else
			{
				UserInfo objUser = (UserInfo)HttpContext.Current.Items["UserInfo"];
				if (objUser != null)
				{
					return objUser;
				}
				else
				{
					return new UserInfo();
				}
			}
		}
		public static ArrayList GetOnlineUsers(int PortalId)
		{
			return memberProvider.GetOnlineUsers(PortalId);
		}
		public static string GetPassword(ref UserInfo user, string passwordAnswer)
		{
			if (MembershipProviderConfig.PasswordRetrievalEnabled)
			{
				user.Membership.Password = memberProvider.GetPassword(user, passwordAnswer);
			}
			else
			{
				throw new ConfigurationErrorsException("Password Retrieval is not enabled");
			}
			return user.Membership.Password;
		}
		/// -----------------------------------------------------------------------------
		/// <summary>
		/// GetUnAuthorizedUsers gets all the users of the portal, that are not authorized
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <param name="portalId">The Id of the Portal</param>
		/// <param name="includeDeleted">Include Deleted users</param>
		/// <param name="superUsersOnly">Bring back super users only</param>        
		/// <returns>An ArrayList of UserInfo objects.</returns>
		/// <history>
		///     [aprasad]	2/18/2011	created
		/// </history>
		/// -----------------------------------------------------------------------------
		public static ArrayList GetUnAuthorizedUsers(int portalId, bool includeDeleted, bool superUsersOnly)
		{
			return memberProvider.GetUnAuthorizedUsers(portalId, includeDeleted, superUsersOnly);
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// GetUnAuthorizedUsers gets all the non-deleted users of the portal, that are not authorized
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <param name="portalId">The Id of the Portal</param>
		/// <returns>An ArrayList of UserInfo objects.</returns>
		/// <history>
		///     [cnurse]	7/11/2006	created        
		///     [aprasad]	2/18/2011	call new overload with Deleted and SuperUsersOnly parameters as False
		/// </history>
		/// -----------------------------------------------------------------------------
		public static ArrayList GetUnAuthorizedUsers(int portalId)
		{
			return GetUnAuthorizedUsers(portalId, false, false);
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// GetDeletedUsers gets all the users of the portal, that are deleted
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <param name="portalId">The Id of the Portal</param>
		/// <returns>An ArrayList of UserInfo objects.</returns>
		/// <history>
		///     [aprasad]	2/15/2011	created
		/// </history>
		/// -----------------------------------------------------------------------------
		public static ArrayList GetDeletedUsers(int portalId)
		{
			return memberProvider.GetDeletedUsers(portalId);
		}
		public static UserInfo GetUserById(int portalId, int userId)
		{
			return memberProvider.GetUser(portalId, userId);
		}
		public static UserInfo GetUserByName(int portalId, string username)
		{
			return GetCachedUser(portalId, username);
		}
		public static int GetUserCountByPortal(int portalId)
		{
			string cacheKey = String.Format(DataCache.PortalUserCountCacheKey, portalId);
			return
				CBO.GetCachedObject<int>(
					new CacheItemArgs(cacheKey, DataCache.PortalUserCountCacheTimeOut, DataCache.PortalUserCountCachePriority, portalId),
					GetUserCountByPortalCallBack);

		}
		public static string GetUserCreateStatus(UserCreateStatus UserRegistrationStatus)
		{
			switch (UserRegistrationStatus)
			{
				case UserCreateStatus.DuplicateEmail:
					return Localization.GetString("UserEmailExists");
				case UserCreateStatus.InvalidAnswer:
					return Localization.GetString("InvalidAnswer");
				case UserCreateStatus.InvalidEmail:
					return Localization.GetString("InvalidEmail");
				case UserCreateStatus.InvalidPassword:
					string strInvalidPassword = Localization.GetString("InvalidPassword");
					strInvalidPassword = strInvalidPassword.Replace("[PasswordLength]", MembershipProviderConfig.MinPasswordLength.ToString());
					strInvalidPassword = strInvalidPassword.Replace("[NoneAlphabet]", MembershipProviderConfig.MinNonAlphanumericCharacters.ToString());
					return strInvalidPassword;
				case UserCreateStatus.PasswordMismatch:
					return Localization.GetString("PasswordMismatch");
				case UserCreateStatus.InvalidQuestion:
					return Localization.GetString("InvalidQuestion");
				case UserCreateStatus.InvalidUserName:
					return Localization.GetString("InvalidUserName");
				case UserCreateStatus.UserRejected:
					return Localization.GetString("UserRejected");
				case UserCreateStatus.DuplicateUserName:
				case UserCreateStatus.UserAlreadyRegistered:
				case UserCreateStatus.UsernameAlreadyExists:
					return Localization.GetString("UserNameExists");
				case UserCreateStatus.ProviderError:
				case UserCreateStatus.DuplicateProviderUserKey:
				case UserCreateStatus.InvalidProviderUserKey:
					return Localization.GetString("RegError");
				default:
					throw new ArgumentException("Unknown UserCreateStatus value encountered", "UserRegistrationStatus");
			}
		}
		public static void GetUserMembership(UserInfo objUser)
		{
			memberProvider.GetUserMembership(ref objUser);
		}
		public static Hashtable GetDefaultUserSettings()
		{
			return GetUserSettings(new Hashtable());
		}
		public static Hashtable GetUserSettings(int portalId)
		{
			Hashtable settings = GetDefaultUserSettings();
			Dictionary<string, string> settingsDictionary;
			if (portalId == Null.NullInteger)
			{
				settingsDictionary = HostController.Instance.GetSettingsDictionary();
			}
			else
			{
				settingsDictionary = PortalController.GetPortalSettingsDictionary(portalId);
			}
			if (settingsDictionary != null)
			{
				string prefix;
				int index;
				foreach (KeyValuePair<string, string> kvp in settingsDictionary)
				{
					index = kvp.Key.IndexOf("_");
					if (index > 0)
					{
						prefix = kvp.Key.Substring(0, index + 1);
						switch (prefix)
						{
							case "Column_":
							case "Display_":
							case "Profile_":
							case "Records_":
							case "Redirect_":
							case "Security_":
								settings[kvp.Key] = kvp.Value;
								break;
						}
					}
				}
			}
			return settings;
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// GetUsers gets all the non-deleted users of the portal
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <param name="portalId">The Id of the Portal</param>
		/// <returns>An ArrayList of UserInfo objects.</returns>
		/// <history>
		///     [cnurse]	7/11/2006	created
		///     [aprasad]	2/16/2011	call new overload with Deleted and SuperUsersOnly parameters as False
		/// </history>
		/// -----------------------------------------------------------------------------
		public static ArrayList GetUsers(int portalId)
		{
			return GetUsers(false, false, portalId);
		}
		/// -----------------------------------------------------------------------------
		/// <summary>
		/// GetUsers gets all the users of the portal
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <param name="includeDeleted">Include Deleted users</param>
		/// <param name="superUsersOnly">Bring back super users only</param>
		/// <param name="portalId">The Id of the Portal</param>
		/// <returns>An ArrayList of UserInfo objects.</returns>
		/// <history>
		///     [aprasad]	2/16/2011	created - new overload with Deletion option
		/// </history>
		/// -----------------------------------------------------------------------------
		public static ArrayList GetUsers(bool includeDeleted, bool superUsersOnly, int portalId)
		{
			int totalRecords = -1;
			return GetUsers(portalId, -1, -1, ref totalRecords, includeDeleted, superUsersOnly);
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// GetUsers gets all the users of the portal, by page
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <param name="portalId">The Id of the Portal</param>
		/// <param name="pageIndex">The page of records to return.</param>
		/// <param name="pageSize">The size of the page</param>
		/// <param name="totalRecords">The total no of records that satisfy the criteria.</param>
		/// <param name="includeDeleted">Include Deleted users</param>
		/// <param name="superUsersOnly">Bring back super users only</param>
		/// <returns>An ArrayList of UserInfo objects.</returns>
		/// <history>
		///     [aprasad]	2/16/2011	created - new overload with Deletion option
		/// </history>
		/// -----------------------------------------------------------------------------
		public static ArrayList GetUsers(int portalId, int pageIndex, int pageSize, ref int totalRecords, bool includeDeleted, bool superUsersOnly)
		{
			return memberProvider.GetUsers(portalId, pageIndex, pageSize, ref totalRecords, includeDeleted, superUsersOnly);
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// GetUsers gets all the non-deleted users of the portal, by page
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <param name="portalId">The Id of the Portal</param>
		/// <param name="pageIndex">The page of records to return.</param>
		/// <param name="pageSize">The size of the page</param>
		/// <param name="totalRecords">The total no of records that satisfy the criteria.</param>
		/// <returns>An ArrayList of UserInfo objects.</returns>
		/// <history>
		///     [cnurse]	7/11/2006	created
		///     [aprasad]	2/16/2011	call new overload with Deleted parameter as False
		/// </history>
		/// -----------------------------------------------------------------------------
		public static ArrayList GetUsers(int portalId, int pageIndex, int pageSize, ref int totalRecords)
		{
			return GetUsers(portalId, pageIndex, pageSize, ref totalRecords, false, false);
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// GetUsersByEmail gets all the users of the portal whose email matches a provided
		/// filter expression
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <param name="portalId">The Id of the Portal</param>
		/// <param name="emailToMatch">The email address to use to find a match.</param>
		/// <param name="pageIndex">The page of records to return.</param>
		/// <param name="pageSize">The size of the page</param>
		/// <param name="totalRecords">The total no of records that satisfy the criteria.</param>
		/// <param name="includeDeleted">Include Deleted users</param>
		/// <param name="superUsersOnly">Bring back super users only</param>
		/// <returns>An ArrayList of UserInfo objects.</returns>
		/// <history>
		///     [aprasad]	2/16/2011	created - new overload with Deletion option
		/// </history>
		/// -----------------------------------------------------------------------------
		public static ArrayList GetUsersByEmail(int portalId, string emailToMatch, int pageIndex, int pageSize, ref int totalRecords, bool includeDeleted, bool superUsersOnly)
		{
			return memberProvider.GetUsersByEmail(portalId, emailToMatch, pageIndex, pageSize, ref totalRecords, includeDeleted, superUsersOnly);
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// GetUsersByEmail gets all the non-deleted users of the portal whose email matches a provided
		/// filter expression
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <param name="portalId">The Id of the Portal</param>
		/// <param name="emailToMatch">The email address to use to find a match.</param>
		/// <param name="pageIndex">The page of records to return.</param>
		/// <param name="pageSize">The size of the page</param>
		/// <param name="totalRecords">The total no of records that satisfy the criteria.</param>
		/// <returns>An ArrayList of UserInfo objects.</returns>
		/// <history>
		///     [cnurse]	7/11/2006	created
		///     [aprasad]	2/16/2011	call new overload with Deleted parameter as False
		/// </history>
		/// -----------------------------------------------------------------------------
		public static ArrayList GetUsersByEmail(int portalId, string emailToMatch, int pageIndex, int pageSize, ref int totalRecords)
		{
			return GetUsersByEmail(portalId, emailToMatch, pageIndex, pageSize, ref totalRecords, false, false);
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// GetUsersByUserName gets all the users of the portal whose username matches a provided
		/// filter expression
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <param name="portalId">The Id of the Portal</param>
		/// <param name="userNameToMatch">The username to use to find a match.</param>
		/// <param name="pageIndex">The page of records to return.</param>
		/// <param name="pageSize">The size of the page</param>
		/// <param name="totalRecords">The total no of records that satisfy the criteria.</param>
		/// <param name="includeDeleted">Include Deleted users</param>
		/// <param name="superUsersOnly">Bring back super users only</param>
		/// <returns>An ArrayList of UserInfo objects.</returns>
		/// <history>
		///     [aprasad]	2/17/2011	created
		/// </history>
		/// -----------------------------------------------------------------------------
		public static ArrayList GetUsersByUserName(int portalId, string userNameToMatch, int pageIndex, int pageSize, ref int totalRecords, bool includeDeleted, bool superUsersOnly)
		{
			return memberProvider.GetUsersByUserName(portalId, userNameToMatch, pageIndex, pageSize, ref totalRecords, includeDeleted, superUsersOnly);
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// GetUsersByUserName gets all the non-deleted users of the portal whose username matches a provided
		/// filter expression
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <param name="portalId">The Id of the Portal</param>
		/// <param name="userNameToMatch">The username to use to find a match.</param>
		/// <param name="pageIndex">The page of records to return.</param>
		/// <param name="pageSize">The size of the page</param>
		/// <param name="totalRecords">The total no of records that satisfy the criteria.</param>
		/// <returns>An ArrayList of UserInfo objects.</returns>
		/// <history>
		///     [cnurse]	7/11/2006	created
		///     [aprasad]	2/16/2011	call new overload with Deleted parameter as False
		/// </history>
		/// -----------------------------------------------------------------------------
		public static ArrayList GetUsersByUserName(int portalId, string userNameToMatch, int pageIndex, int pageSize, ref int totalRecords)
		{
			return GetUsersByUserName(portalId, userNameToMatch, pageIndex, pageSize, ref totalRecords, false, false);
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// GetUsersByProfileProperty gets all the users of the portal whose profile matches
		/// the profile property pased as a parameter
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <param name="portalId">The Id of the Portal</param>
		/// <param name="propertyName">The name of the property being matched.</param>
		/// <param name="propertyValue">The value of the property being matched.</param>
		/// <param name="pageIndex">The page of records to return.</param>
		/// <param name="pageSize">The size of the page</param>
		/// <param name="totalRecords">The total no of records that satisfy the criteria.</param>
		/// <returns>An ArrayList of UserInfo objects.</returns>
		/// <history>
		///     [cnurse]	2/17/2011	created
		/// </history>
		/// -----------------------------------------------------------------------------
		public static ArrayList GetUsersByProfileProperty(int portalId, string propertyName, string propertyValue, int pageIndex, int pageSize, ref int totalRecords, bool includeDeleted, bool superUsersOnly)
		{
			return memberProvider.GetUsersByProfileProperty(portalId, propertyName, propertyValue, pageIndex, pageSize, ref totalRecords, includeDeleted, superUsersOnly);
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// GetUsersByProfileProperty gets all the non-deleted users of the portal whose profile matches
		/// the profile property pased as a parameter
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <param name="portalId">The Id of the Portal</param>
		/// <param name="propertyName">The name of the property being matched.</param>
		/// <param name="propertyValue">The value of the property being matched.</param>
		/// <param name="pageIndex">The page of records to return.</param>
		/// <param name="pageSize">The size of the page</param>
		/// <param name="totalRecords">The total no of records that satisfy the criteria.</param>
		/// <returns>An ArrayList of UserInfo objects.</returns>
		/// <history>
		///     [cnurse]	7/11/2006	created
		///     [aprasad]	2/16/2011	call new overload with Deleted parameter as False
		/// </history>
		/// -----------------------------------------------------------------------------
		public static ArrayList GetUsersByProfileProperty(int portalId, string propertyName, string propertyValue, int pageIndex, int pageSize, ref int totalRecords)
		{
			return GetUsersByProfileProperty(portalId, propertyName, propertyValue, pageIndex, pageSize, ref totalRecords, false, false);
		}

		public static string ResetPassword(UserInfo user, string passwordAnswer)
		{
			if (MembershipProviderConfig.PasswordResetEnabled)
			{
				user.Membership.Password = memberProvider.ResetPassword(user, passwordAnswer);
			}
			else
			{
				throw new ConfigurationErrorsException("Password Reset is not enabled");
			}
			return user.Membership.Password;
		}
		public static void SetAuthCookie(string username, bool CreatePersistentCookie)
		{
		}
		public static string SettingsKey(int portalId)
		{
			return "UserSettings|" + portalId.ToString();
		}
		public static bool UnLockUser(UserInfo user)
		{
			bool retValue = false;
			retValue = memberProvider.UnLockUser(user);
			DataCache.ClearUserCache(user.PortalID, user.Username);
			return retValue;
		}
		public static void UpdateUser(int portalId, UserInfo objUser)
		{
			UpdateUser(portalId, objUser, true);
		}
		/// <summary>
		/// updates a user
		/// </summary>
		/// <param name="portalId">the portalid of the user</param>
		/// <param name="objUser">the user object</param>
		/// <param name="loggedAction">whether or not the update calls the eventlog - the eventlogtype must still be enabled for logging to occur</param>
		/// <remarks></remarks>
		public static void UpdateUser(int portalId, UserInfo objUser, bool loggedAction)
		{
			//Update the User
			memberProvider.UpdateUser(objUser);
			if (loggedAction)
			{
				Services.Log.EventLog.EventLogController objEventLog = new Services.Log.EventLog.EventLogController();
				objEventLog.AddLog(objUser, PortalController.GetCurrentPortalSettings(), UserController.GetCurrentUserInfo().UserID, "", DotNetNuke.Services.Log.EventLog.EventLogController.EventLogType.USER_UPDATED);
			}
			DataCache.ClearUserCache(portalId, objUser.Username);
		}
		public static UserInfo UserLogin(int portalId, string Username, string Password, string VerificationCode, string PortalName, string IP, ref UserLoginStatus loginStatus, bool CreatePersistentCookie)
		{
			loginStatus = UserLoginStatus.LOGIN_FAILURE;
			UserInfo objUser = ValidateUser(portalId, Username, Password, VerificationCode, PortalName, IP, ref loginStatus);
			if (objUser != null)
			{
				UserLogin(portalId, objUser, PortalName, IP, CreatePersistentCookie);
			}
			else
			{
				AddEventLog(portalId, Username, Null.NullInteger, PortalName, IP, loginStatus);
			}
			return objUser;
		}
		public static void UserLogin(int portalId, UserInfo user, string PortalName, string IP, bool CreatePersistentCookie)
		{
			if (user.IsSuperUser)
			{
				AddEventLog(portalId, user.Username, user.UserID, PortalName, IP, UserLoginStatus.LOGIN_SUPERUSER);
			}
			else
			{
				AddEventLog(portalId, user.Username, user.UserID, PortalName, IP, UserLoginStatus.LOGIN_SUCCESS);
			}
			user.LastIPAddress = IP;
			UserController.UpdateUser(portalId, user);
			FormsAuthentication.SetAuthCookie(user.Username, CreatePersistentCookie);
			int PersistentCookieTimeout = Config.GetPersistentCookieTimeout();
			if (CreatePersistentCookie == true)
			{
				FormsAuthenticationTicket AuthenticationTicket = new FormsAuthenticationTicket(user.Username, true, PersistentCookieTimeout);
				string EncryptedAuthTicket = FormsAuthentication.Encrypt(AuthenticationTicket);
				HttpCookie AuthCookie = new HttpCookie(FormsAuthentication.FormsCookieName, EncryptedAuthTicket);
				AuthCookie.Expires = AuthenticationTicket.Expiration;
				AuthCookie.Domain = FormsAuthentication.CookieDomain;
				AuthCookie.Path = FormsAuthentication.FormsCookiePath;
				HttpContext.Current.Response.Cookies.Set(AuthCookie);
			}
		}
		public static bool ValidatePassword(string password)
		{
			bool isValid = true;
			Regex rx;
			if (password.Length < MembershipProviderConfig.MinPasswordLength)
			{
				isValid = false;
			}
			rx = new Regex("[^0-9a-zA-Z]");
			if (rx.Matches(password).Count < MembershipProviderConfig.MinNonAlphanumericCharacters)
			{
				isValid = false;
			}
			if (!String.IsNullOrEmpty(MembershipProviderConfig.PasswordStrengthRegularExpression) && isValid)
			{
				rx = new Regex(MembershipProviderConfig.PasswordStrengthRegularExpression);
				isValid = rx.IsMatch(password);
			}
			return isValid;
		}
		public static UserInfo ValidateUser(int portalId, string Username, string Password, string VerificationCode, string PortalName, string IP, ref UserLoginStatus loginStatus)
		{
			return ValidateUser(portalId, Username, Password, "DNN", VerificationCode, PortalName, IP, ref loginStatus);
		}
		public static UserInfo ValidateUser(int portalId, string Username, string Password, string authType, string VerificationCode, string PortalName, string IP, ref UserLoginStatus loginStatus)
		{
			loginStatus = UserLoginStatus.LOGIN_FAILURE;
			UserInfo objUser = memberProvider.UserLogin(portalId, Username, Password, authType, VerificationCode, ref loginStatus);
			if (loginStatus == UserLoginStatus.LOGIN_USERLOCKEDOUT || loginStatus == UserLoginStatus.LOGIN_FAILURE)
			{
				AddEventLog(portalId, Username, Null.NullInteger, PortalName, IP, loginStatus);
			}
			if (loginStatus == UserLoginStatus.LOGIN_SUCCESS || loginStatus == UserLoginStatus.LOGIN_SUPERUSER)
			{
				CheckInsecurePassword(Username, Password, ref loginStatus);
			}
			return objUser;
		}
		public static UserValidStatus ValidateUser(UserInfo objUser, int portalId, bool ignoreExpiring)
		{
			UserValidStatus validStatus = UserValidStatus.VALID;
			if (objUser.Membership.UpdatePassword)
			{
				validStatus = UserValidStatus.UPDATEPASSWORD;
			}
			else if (PasswordConfig.PasswordExpiry > 0)
			{
				DateTime expiryDate = objUser.Membership.LastPasswordChangeDate.AddDays(PasswordConfig.PasswordExpiry);
				if (expiryDate < DateTime.Now)
				{
					validStatus = UserValidStatus.PASSWORDEXPIRED;
				}
				else if (expiryDate < DateTime.Now.AddDays(PasswordConfig.PasswordExpiryReminder) && (!ignoreExpiring))
				{
					validStatus = UserValidStatus.PASSWORDEXPIRING;
				}
			}
			if (validStatus == UserValidStatus.VALID)
			{
				bool validProfile = Convert.ToBoolean(UserModuleBase.GetSetting(portalId, "Security_RequireValidProfileAtLogin"));
				if (validProfile && (!ProfileController.ValidateProfile(portalId, objUser.Profile)))
				{
					validStatus = UserValidStatus.UPDATEPROFILE;
				}
			}
			return validStatus;
		}
		private int _PortalId;
		private string _DisplayName;
		public string DisplayFormat
		{
			get { return _DisplayName; }
			set { _DisplayName = value; }
		}
		public int PortalId
		{
			get { return _PortalId; }
			set { _PortalId = value; }
		}
		public UserInfo GetUser(int portalId, int userId)
		{
			return GetUserById(portalId, userId);
		}
		public void UpdateDisplayNames()
		{
			ArrayList arrUsers = GetUsers(PortalId);
			foreach (UserInfo objUser in arrUsers)
			{
				objUser.UpdateDisplayName(DisplayFormat);
				UpdateUser(PortalId, objUser);
			}
		}

		#region "Obsoleted Methods, retained for Binary Compatability"

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.CreateUser")]
		public int AddUser(UserInfo objUser)
		{
			UserCreateStatus createStatus = CreateUser(ref objUser);
			return objUser.UserID;
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.CreateUser")]
		public int AddUser(UserInfo objUser, bool AddToMembershipProvider)
		{
			UserCreateStatus createStatus = CreateUser(ref objUser);
			return objUser.UserID;
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.DeleteUsers")]
		public void DeleteAllUsers(int PortalId)
		{
			DeleteUsers(PortalId, false, true);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.DeleteUser")]
		public bool DeleteUser(int PortalId, int UserId)
		{
			UserInfo objUser = GetUser(PortalId, UserId);

			//Call Shared method with notify=true, deleteAdmin=false
			return DeleteUser(ref objUser, true, false);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.DeleteUsers")]
		public void DeleteUsers(int PortalId)
		{
			DeleteUsers(PortalId, true, false);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.GetUserByName")]
		public UserInfo FillUserInfo(int PortalID, string Username)
		{
			return GetCachedUser(PortalID, Username);
		}

		[Obsolete("Deprecated in DNN 5.1. This function should be replaced by String.Format(DataCache.UserCacheKey, portalId, username)")]
		public string GetCacheKey(int PortalID, string Username)
		{
			return string.Format(DataCache.UserCacheKey, PortalID, Username);
		}

		[Obsolete("Deprecated in DNN 5.1. This function should be replaced by String.Format(DataCache.UserCacheKey, portalId, username)")]
		public static string CacheKey(int portalId, string username)
		{
			return string.Format(DataCache.UserCacheKey, portalId, username);
		}

		[Obsolete("Deprecated in DNN 5.1. Not needed any longer for due to autohydration")]
		public static ArrayList GetUnAuthorizedUsers(int portalId, bool isHydrated)
		{
			return GetUnAuthorizedUsers(portalId);
		}

		[Obsolete("Deprecated in DNN 5.1. Not needed any longer for due to autohydration")]
		public static UserInfo GetUser(int portalId, int userId, bool isHydrated)
		{
			return GetUserById(portalId, userId);
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// GetUser retrieves a User from the DataStore
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <param name="portalId">The Id of the Portal</param>
		/// <param name="userId">The Id of the user being retrieved from the Data Store.</param>
		/// <param name="isHydrated">A flag that determines whether the user is hydrated.</param>
		/// <param name="hydrateRoles">A flag that instructs the method to automatically hydrate the roles</param>
		/// <returns>The User as a UserInfo object</returns>
		/// <history>
		/// </history>
		/// -----------------------------------------------------------------------------
		[Obsolete("Deprecated in DNN 5.1. Not needed any longer for single users due to autohydration")]
		public static UserInfo GetUser(int portalId, int userId, bool isHydrated, bool hydrateRoles)
		{
			UserInfo user = GetUserById(portalId, userId);

			if (hydrateRoles)
			{
				DotNetNuke.Security.Roles.RoleController controller = new DotNetNuke.Security.Roles.RoleController();
				user.Roles = controller.GetRolesByUser(userId, portalId);
			}

			return user;
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.GetUserByName")]
		public UserInfo GetUserByUsername(int PortalID, string Username)
		{
			return GetCachedUser(PortalID, Username);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.GetUserByName")]
		public UserInfo GetUserByUsername(int PortalID, string Username, bool SynchronizeUsers)
		{
			return GetCachedUser(PortalID, Username);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.GetUserByName")]
		public static UserInfo GetUserByName(int portalId, string username, bool isHydrated)
		{
			return GetCachedUser(portalId, username);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.GetUsers")]
		public ArrayList GetSuperUsers()
		{
			return GetUsers(Null.NullInteger);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.GetUsers")]
		public ArrayList GetUsers(bool SynchronizeUsers, bool ProgressiveHydration)
		{
			return GetUsers(Null.NullInteger);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.GetUsers")]
		public ArrayList GetUsers(int PortalId, bool SynchronizeUsers, bool ProgressiveHydration)
		{
			int totalRecords = -1;
			return GetUsers(PortalId, -1, -1, ref totalRecords);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.GetUsers")]
		public static ArrayList GetUsers(int portalId, bool isHydrated)
		{
			int totalRecords = -1;
			return GetUsers(portalId, -1, -1, ref totalRecords);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.GetUsers")]
		public static ArrayList GetUsers(int portalId, bool isHydrated, int pageIndex, int pageSize, ref int totalRecords)
		{
			return GetUsers(portalId, pageIndex, pageSize, ref totalRecords);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.GetUsersByEmail")]
		public static ArrayList GetUsersByEmail(int portalId, bool isHydrated, string emailToMatch, int pageIndex, int pageSize, ref int totalRecords)
		{
			return GetUsersByEmail(portalId, emailToMatch, pageIndex, pageSize, ref totalRecords);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.GetUsersByUserName")]
		public static ArrayList GetUsersByUserName(int portalId, bool isHydrated, string userNameToMatch, int pageIndex, int pageSize, ref int totalRecords)
		{
			return GetUsersByUserName(portalId, userNameToMatch, pageIndex, pageSize, ref totalRecords);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.GetUsersByProfileProperty")]
		public static ArrayList GetUsersByProfileProperty(int portalId, bool isHydrated, string propertyName, string propertyValue, int pageIndex, int pageSize, ref int totalRecords)
		{
			return GetUsersByProfileProperty(portalId, propertyName, propertyValue, pageIndex, pageSize, ref totalRecords);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.ChangePassword")]
		public bool SetPassword(UserInfo objUser, string newPassword)
		{
			return ChangePassword(objUser, Null.NullString, newPassword);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.ChangePassword")]
		public bool SetPassword(UserInfo objUser, string oldPassword, string newPassword)
		{
			return ChangePassword(objUser, oldPassword, newPassword);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.UnlockUserAccount")]
		public void UnlockUserAccount(UserInfo objUser)
		{
			UnLockUser(objUser);
		}

		[Obsolete("Deprecated in DNN 5.1. This function has been replaced by UserController.UpdateUser")]
		public void UpdateUser(UserInfo objUser)
		{
			UpdateUser(objUser.PortalID, objUser);
		}



		#endregion
	}
}
